package com.neusoft.bigdata.hbase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import com.neusoft.bigdata.hbase.biz.impl.StatisticServiceHBaseImpl;
import com.neusoft.bigdata.hbase.model.StatisticData.PeriodType;
import com.neusoft.bigdata.hbase.model.StatisticData.StatisticType;
import com.neusoft.bigdata.hbase.util.CommonUtil;

/**
 * 用于生成准备统计结果数据
 * 
 * @author lihzh
 * @date 2013-4-3 下午4:55:54
 */
public class ForPrepareStatisticData extends CommonUtil {

	public static final long HOUR_INTERVAL = 3600 * 1000L;
	public static final int DAY_COUNT = 30;

	/**
	 * @param args
	 * @author lihzh
	 * @date 2013-4-3 下午4:55:54
	 */
	public static void main(String[] args) {
		long ENDTIME = STARTTIME + DAY_COUNT * 24 * 3600 * 1000L;
		for (int i = 1; i <= RESOURCE_COUNT_ONE; i++) {
			String id = ID_PREFIX + createId(i);
			for (long t = STARTTIME; t < ENDTIME; t += HOUR_INTERVAL) {
				String rowKey = StatisticServiceHBaseImpl.createRowKey(id,
						PeriodType.H.name(), StatisticType.AVG.name(), t);
				Put put = new Put();
				List<KeyValue> kvList = new ArrayList<KeyValue>();
				for (int j = 1; j <= METRIC_COUNT_ONE; j++) {
					String metricName = METRIC_NAME_PREFIX + j;
					KeyValue kv = new KeyValue(Bytes.toBytes(rowKey),
							Bytes.toBytes(CF_NAME_STINFO),
							Bytes.toBytes(metricName),
							Bytes.toBytes(getValue()));
					kvList.add(kv);
				}
				Map<byte[], List<KeyValue>> fMap = new HashMap<byte[], List<KeyValue>>();
				fMap.put(Bytes.toBytes(CF_NAME_STINFO), kvList);
				put.setFamilyMap(fMap);
			}
		}
	}
}
